package com.fxp.project.jiuselu.web.models.article.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fxp.project.jiuselu.commons.utils.ExtractImgUrlUtils;
import com.fxp.project.jiuselu.web.models.article.entity.JslArticle;
import com.fxp.project.jiuselu.web.models.article.mapper.JslArticleMapper;
import com.fxp.project.jiuselu.web.models.article.request.ReqAtricles;
import com.fxp.project.jiuselu.web.models.article.service.IjslArticleService;
import com.fxp.project.jiuselu.web.models.article.vo.ArticleListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资讯Service业务层处理
 *
 * @author Jason.Wang
 * @date 2021-10-18
 */
@Service
public class JslArticleServiceImpl extends ServiceImpl<JslArticleMapper, JslArticle> implements IjslArticleService {

    @Autowired
    private JslArticleMapper articleMapper;

    @Override
    public PageInfo<ArticleListVo> selectArticleListPageInfo(ReqAtricles reqAtricles) {
        PageHelper.startPage(reqAtricles.getPage(), reqAtricles.getSize());
        List<ArticleListVo> articleListVos = articleMapper.selectArticleList(reqAtricles);
        for (ArticleListVo vo : articleListVos) {
            vo.setShowImageUrl(ExtractImgUrlUtils.getFirstImgUrl(vo.getArticleContent()));
        }
        return new PageInfo<>(articleListVos);
    }
}
